import Operator from "./Operator";
import { RC } from "../config/RC";
import MessageBox from "../entities/MessageBox";
import Users from "../entities/User";
import Group from "../entities/Group";
import { USER, GROUP } from "../config/config";

class GetFriendAndGroupOperator extends Operator {
    public async execute(): Promise<RC> {
        const userId = this.args.getProperty('userId');
        let information: Array<{ type: string, id: string, name: string }> = [];

        // 获取用户信息
        const friends = await Users.getFriends(userId);

        // 获取好友信息
        for (const friendId of friends) {
            const friendName = await Users.getName(friendId);
            if (friendName) {
                information.push({ type: USER, id: friendId, name: friendName });
            }
        }

        // 获取用户所属的群组信息
        const userGroups = await Group.getUserGroups(userId);
        information = information.concat(userGroups);

        // 将结果设置到 args 中返回
        this.args.setProperty('information', information);
        return RC.SUCCESS;
    }
}

export default GetFriendAndGroupOperator;
